<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<style>
    #costSheet th {
        background: #FFFFFF;
    }

    #costSheet td {
        background: #FFFFFF;
    }

    .loadEffect {
        width: 100px;
        height: 100px;
        position: relative;
        margin: 0 auto;
        margin-top: 100px;
    }

    .loadEffect span {
        display: inline-block;
        width: 16px;
        height: 16px;
        border-radius: 50%;
        background: lightgreen;
        position: absolute;
        -webkit-animation: load 1.04s ease infinite;
    }

    @-webkit-keyframes load {
        0% {
            opacity: 1;
        }
        100% {
            opacity: 0.2;
        }
    }

    .loadEffect span:nth-child(1) {
        left: 0;
        top: 50%;
        margin-top: -8px;
        -webkit-animation-delay: 0.13s;
    }

    .loadEffect span:nth-child(2) {
        left: 14px;
        top: 14px;
        -webkit-animation-delay: 0.26s;
    }

    .loadEffect span:nth-child(3) {
        left: 50%;
        top: 0;
        margin-left: -8px;
        -webkit-animation-delay: 0.39s;
    }

    .loadEffect span:nth-child(4) {
        top: 14px;
        right: 14px;
        -webkit-animation-delay: 0.52s;
    }

    .loadEffect span:nth-child(5) {
        right: 0;
        top: 50%;
        margin-top: -8px;
        -webkit-animation-delay: 0.65s;
    }

    .loadEffect span:nth-child(6) {
        right: 14px;
        bottom: 14px;
        -webkit-animation-delay: 0.78s;
    }

    .loadEffect span:nth-child(7) {
        bottom: 0;
        left: 50%;
        margin-left: -8px;
        -webkit-animation-delay: 0.91s;
    }

    .loadEffect span:nth-child(8) {
        bottom: 14px;
        left: 14px;
        -webkit-animation-delay: 1.04s;
    }

    .loadEffect {
        width: 100px;
        height: 100px;
        position: relative;
        margin: 0 auto;
        margin-top: 100px;
    }

    .loadEffect span {
        display: inline-block;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: lightgreen;
        position: absolute;
        -webkit-animation: load 1.04s ease infinite;
    }

    @-webkit-keyframes load {
        0% {
            -webkit-transform: scale(1.2);
            opacity: 1;
        }
        100% {
            -webkit-transform: scale(.3);
            opacity: 0.5;
        }
    }

    .loadEffect span:nth-child(1) {
        left: 0;
        top: 50%;
        margin-top: -10px;
        -webkit-animation-delay: 0.13s;
    }

    .loadEffect span:nth-child(2) {
        left: 14px;
        top: 14px;
        -webkit-animation-delay: 0.26s;
    }

    .loadEffect span:nth-child(3) {
        left: 50%;
        top: 0;
        margin-left: -10px;
        -webkit-animation-delay: 0.39s;
    }

    .loadEffect span:nth-child(4) {
        top: 14px;
        right: 14px;
        -webkit-animation-delay: 0.52s;
    }

    .loadEffect span:nth-child(5) {
        right: 0;
        top: 50%;
        margin-top: -10px;
        -webkit-animation-delay: 0.65s;
    }

    .loadEffect span:nth-child(6) {
        right: 14px;
        bottom: 14px;
        -webkit-animation-delay: 0.78s;
    }

    .loadEffect span:nth-child(7) {
        bottom: 0;
        left: 50%;
        margin-left: -10px;
        -webkit-animation-delay: 0.91s;
    }

    .loadEffect span:nth-child(8) {
        bottom: 14px;
        left: 14px;
        -webkit-animation-delay: 1.04s;
    }


</style>
<body class="hold-transition skin-blue sidebar-mini" onmousedown="xyh.disableRight()"
      oncontextmenu="xyh.disableRight()">

<!--编辑计算参数模态框-->
<div class="modal fade" id="modal-edit-parameter">
    <div class="modal-dialog" style="width:1300px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">计算参数</h4>
            </div>
            <form id="edit-parameter-form" class="form-horizontal">
                <div class="modal-header">
                    <div class="col-md-12 row" style="font-weight: bold">
                        <div id="edit-parameter-form-items" class="form-inline">

                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-info file-contract btn-file" th:data="${batId}"
                            id="btn-save-edit">保存
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!--锁屏模态框-->
<div class="modal fade" id="modal-lock" data-backdrop="false" data-keyboard="false">
    <div class="modal-dialog" style="width:1300px">
        <div class="modal-content" style="background: transparent;margin-top:350px; ">
            <div class="loadEffect">
                <span></span>
                <span></span>
                <span></span>
                <span></span>
                <span></span>
                <span></span>
                <span></span>
                <span></span>
            </div>
        </div>
    </div>
</div>


<!--编辑模态框-->
<div class="modal fade" id="modal-item-edit">
    <div class="modal-dialog" style="width:1300px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 id="modal-title" class="modal-title">信息编辑</h4>
            </div>
            <form id="edit-form" class="form-horizontal">
                <div class="modal-header">
                    <div class="col-md-12 row" style="font-weight: bold">
                        <div style="display: none">
                            <input name="id" type="hidden" style="display: none"/>
                        </div>
                        <!--                        <div class="form-group col-sm-6">-->
                        <!--                            <label class="control-label" style="width: 60px;">序号：</label>-->
                        <!--                            <label class="control-label">-->
                        <!--                                <input name="editShowOrderNo" class="form-control" type="text" maxlength="255"/>-->
                        <!--                            </label>-->
                        <!--                        </div>-->
                        <div class="form-group col-sm-6">
                            <label class="control-label" style="width: 100px;">名称：</label>
                            <label class="control-label">
                                <span class="form-control" style="width: 215px;text-align: left" id="name"></span>
                            </label>
                        </div>
                        <div class="form-group col-sm-6" id="texture" style="display: none">
                            <label class="control-label" style="width: 100px;">材质</label>
                            <label class="control-label">
                                <input name="texture" class="form-control" type="text" maxlength="255"/>
                            </label>
                        </div>
                        <div class="form-group col-sm-6" id="num">
                            <label class="control-label" style="width: 100px;">数量：</label>
                            <label class="control-label">
                                <input name="num" class="form-control" oninput="formatNumber(this)" type="text"
                                       maxlength="20"/>
                            </label>
                        </div>
                        <div class="form-group col-sm-6" id="price">
                            <label class="control-label" style="width: 100px;">单价：</label>
                            <label class="control-label">
                                <input name="price" class="form-control" type="text" oninput="formatNumber(this)"
                                       maxlength="20"/>
                            </label><label class="control-label">&nbsp;&nbsp;元</label>
                        </div>
                        <div class="form-group col-sm-6" id="totalPrice">
                            <label class="control-label" style="width: 100px;">总价：</label>
                            <label class="control-label">
                                <input name="totalPrice" class="form-control" type="text" oninput="formatNumber(this)"
                                       maxlength="20"/>
                            </label><label class="control-label">&nbsp;&nbsp;元</label>
                        </div>
                        <div class="form-group col-sm-6" id="trueAmount">
                            <label class="control-label" style="width: 100px;">真实金额：</label>
                            <label class="control-label">
                                <input name="trueAmount" class="form-control" type="text" oninput="formatNumber(this)"
                                       maxlength="20"/>
                            </label><label class="control-label">&nbsp;&nbsp;元</label>
                        </div>
                        <div class="form-group col-sm-6" id="remark">
                            <label class="control-label" style="width: 100px;">附加信息：</label>
                            <label class="control-label">
                                <input name="diyRemark" class="form-control" type="text" maxlength="255"/>
                            </label>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button shiro:hasPermission="ver:adjust:edit" type="button"
                            class="btn btn-info file-contract btn-file" th:data="${batId}" id="btn-costItem-save">保存
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!--新增项模态框-->
<div class="modal fade" id="modal-item-add">
    <div class="modal-dialog" style="width:1300px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">新增项编辑</h4>
            </div>
            <form id="add-form" class="form-horizontal">
                <div class="modal-header">
                    <div class="col-md-12 row" style="font-weight: bold">
                        <div style="display: none">
                            <input name="batId" type="hidden" style="display: none"/>
                            <input name="parentCode" type="hidden" style="display: none"/>
                        </div>
                        <div class="form-group col-sm-6">
                            <label class="control-label" style="width: 100px;">名称：</label>
                            <label class="control-label">
                                <input name="name" type="text" class="form-control" maxlength="255"
                                       oninput="handlingSpaces(this)"/>
                            </label>
                        </div>
                        <div class="form-group col-sm-6">
                            <label class="control-label" style="width: 100px;">真实金额：</label>
                            <label class="control-label">
                                <input name="trueAmount" class="form-control" type="text" oninput="formatNumber(this)"
                                       maxlength="20"/>
                            </label><label class="control-label">&nbsp;&nbsp;元</label>
                        </div>
                        <div class="form-group col-sm-6">
                            <label class="control-label" style="width: 100px;">附加信息：</label>
                            <label class="control-label">
                                <input name="diyRemark" class="form-control" type="text" maxlength="255"/>
                            </label>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button shiro:hasPermission="rou:adjust:edit" type="button"
                            class="btn btn-info file-contract btn-file" th:data="${batId}" id="btn-costItem-add-save">保存
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </form>
        </div>
    </div>
</div>
<section class="content-header">
    <h1 style="display: inline-block">成本概算清单（单台/套）编辑</h1>
    <div class="form-group pull-right" style="margin-right: 100px">
        <label class="control-label">
            <button id="btn-save-estimating" class="btn btn-success btn-xs">
                保存至提交
            </button>
        </label>
        <label class="control-label">
            <button id="btn-full-screen" screen-status="未全屏" class="btn btn-success btn-xs">
                点击全屏
            </button>
        </label>
    </div>
    <a th:href="@{/accountManage}" type="button" class="btn btn-success pull-right"
       style="text-align:center;vertical-align:middle;font-size:30px;position:absolute;right:3%;display: inline-block;background-color: transparent;border: none;color: #5c5c5c;outline:none;">
        <i style="-moz-transform:scaleX(-1);-webkit-transform:scaleX(-1);-o-transform:scaleX(-1);transform:scaleX(-1);filter:FlipH;"
           class="glyphicon glyphicon-share-alt"></i><span
            style="margin-left: 5px;font-size: 16px;position: absolute;top: 20%;">返回</span>
    </a>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="row" th:if="${reject != null and reject.appStatus == 0}">
                        <div class="form-inline">
                            <label class="control-label">驳回意见：</label>
                            <textarea th:text="${reject.remark}" readonly="readonly">
                            </textarea>
                        </div>
                    </div>
                    <div class="row" style="line-height: 40px;border-bottom: #D2D6DE 3px solid;vertical-align: middle">
                        <div class="form-inline">
                            <div class="form-group">
                                <label class="control-label">
                                    项目编号：
                                </label>
                                <label class="control-label" th:text="${project.code}"></label>
                                <input id="code" type="hidden" th:value="${project.code}" style="display: none">
                                <input id="batId" type="hidden" th:value="${batId}" style="display: none">
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    项目名称：
                                </label>
                                <label class="control-label" th:text="${project.name}"></label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    需方：
                                </label>
                                <label class="control-label" th:text="${project.demander}"></label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    安装地点：
                                </label>
                                <label class="control-label" th:text="${project.address}"></label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    项目数量：
                                </label>
                                <label id="proNum" class="control-label" th:text="${project.num}"></label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    设计类别：
                                </label>
                                <label class="control-label"
                                       th:text="${project.projectClassify == 1 ? '设计':'非设计'}"></label>
                            </div>
                        </div>
                    </div>
                    <div class="row" style="line-height: 40px;border-bottom: #D2D6DE 3px solid;vertical-align: middle">
                        <div class="form-inline">
                            <div class="form-group" shiro:hasPermission="ver:adjust:edit">
                                <label class="control-label">
                                    <button class="btn btn-default" style="width: 150px" th:data="${batId}"
                                            onclick="showEditCalculationParameter(this)">
                                        <i class="fa fa-edit"></i>
                                        编辑计算参数
                                    </button>
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="row" style="border-bottom: #D2D6DE 3px solid;vertical-align: middle">
                        <div id="basicInfoPanel" class="row" style="line-height: 10px;padding-top:10px">
                            <div id="parameterDisplayPanel" class="form-inline">
                            </div>
                        </div>
                    </div>
                    <div id="mainParameterPanel" class="row"
                         style="border-bottom: #D2D6DE 3px solid;vertical-align: middle;padding: 10px 0px 0px 15px;">
                        <div class="form-group" style="margin-bottom: 0px;">
                            <label class="control-label">
                                主要参数：
                            </label>
                            <label class="control-label" style="width: 600px;">
                                <input type="text" id="mainParameter" maxlength="500"
                                       style="width: 560px;height: 35px;font-size: 16px;"/>
                            </label>
                            <label class="control-label">
                                <button id="btn-save-mainParameter" class="btn btn-success btn-xs" type="button">
                                    保存主要参数
                                </button>
                            </label>
                        </div>
                    </div>
                    <div class="row" style="line-height: 45px;">
                        <div class="form-inline">
                            <div class="form-group">
                                <label class="control-label">
                                    <button id="btn-estimating" class="btn btn-success">
                                        一键概算
                                    </button>
                                </label>
                            </div>
                            <div class="btn-group pull-right">
                                <select id="listDisplayMode" class="selectpicker" onChange="switchModel()">
                                    <option value="-1">显示全部</option>
                                    <option value="1">显示未删项</option>
                                </select>
                            </div>
                            <div class="btn-group pull-right" style="margin-right: 20px;">
                                <label class="control-label">
                                    金额单位显示模式：
                                </label>
                                <select id="listDisplayAmountMode" class="selectpicker"
                                        onChange="switchAmountModel(this)">
                                    <option value="1">元</option>
                                    <option value="2">万元</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="nav">
                        <!-- 导航 -->
                        <ul class="nav nav-tabs" role="tablist">
                            <li role="presentation" class="active"><a href="#all" aria-controls="all" role="tab"
                                                                      data-toggle="tab">项目整体成本</a></li>
                            <li class="pull-right" style="margin-right: 10%;font-size: 16px;"><label
                                    class="control-label">设备总重/净重（单台）：</label><label id="equipmentTotalWeight"
                                                                                     class="control-label">111吨</label><label
                                    class="control-label">/</label><label id="equipmentTotalNetWeight"
                                                                          class="control-label">11吨</label></li>
                        </ul>
                        <div class="tab-content">
                            <div role="tabpanel" class="tab-pane fade in active" id="all"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let costIdAll;
    function getMousePos(event) {
        var e = event || window.event;
        var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
        var x = e.pageX || e.clientX + scrollX;
        return x;
    }
    $(function () {
        /**
         * H5表格行级拖拽
         **/
        $.fn.dragSort = function () {
            let $tr, $tr_drag, $tr_drop;
            let positionX;
            $tr = $(this).find("tr");
            $tr.prop("draggable", "true");
            //移除选中样式
            $tr.on("click", function () {
                $("#dataRow_" + costIdAll).find('td').removeClass('bg-orange');
            });
            $tr.on("dragstart", function () {
                $tr_drag = $(this);
                positionX = getMousePos();
            }).on("dragleave", function (e) {
                $tr_drop.removeClass("alert-success");
            }).on("dragover", function (e) {
                $tr_drop = $(e.target).parent("tr");
                $tr_drop.addClass("alert-success");
                e.preventDefault();
            }).on("drop", function (e) {
                $tr_drop.removeClass("alert-success");
                $(this).before($tr_drag);
                let $prevItem = $(this);
                js.post({
                    url: ctx + 'accountManage/changeOrder',
                    type: 'post',
                    traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                    dataType: 'json',
                    contentType: "application/x-www-form-urlencoded",
                    data: {
                        dragItemId: $tr_drag.attr("data-id"),
                        prevItemId: $prevItem.attr("data-id")
                    },
                    async: true,                // 异步执行
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            js.modal.success(result.msg);
                            loadCostSheet();
                        } else {
                            js.modal.warning(result.msg);
                            loadCostSheet();
                        }
                    },
                    error: function () {
                        js.modal.fail();
                    }
                })
            });
        };
        loadControlDropDownMenuDisplayParameters();
        loadWeightParams();
        loadConfigParams();
        loadMainParam();
        loadCostSheet();
        $("#costSheet [name='num']").each(function () {
            if ($(this).text() != '') {
                let resultNumber = dealingWithDecimals($(this).text());
                $(this).text(resultNumber);
            }
        });
        $("#costSheet [name='price']").each(function () {
            if ($(this).text() != '') {
                let resultNumber = dealingWithDecimals($(this).text());
                $(this).text(resultNumber);
            }
        });
        $("#costSheet [name='totalPrice']").each(function () {
            if ($(this).text() != '') {
                let resultNumber = dealingWithDecimals($(this).text());
                $(this).text(resultNumber);
            }
        });
        /**
         * 重新生成当前清单
         */
        $("#btn-regenerate-cost-sheet").on('click', function (e) {
            js.confirmPost({
                content: "尊敬的用户，重新生成此表单会清空此表单的一切数据，您确认要重新生成此表单吗？",
                url: ctx + 'accountManage/regenerateCostSheet',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: {
                    code: $("#code").val(),
                    batId: $("#batId").val()
                },
                async: true,                // 异步执行
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        location.reload();
                    } else {
                        js.modal.warning(result.msg);
                    }
                },
                error: function () {
                    js.modal.fail();
                }
            })
        });

        /**
         * 保存编辑好的计算参数
         * */
        $("#btn-save-edit").on('click', function (e) {
            let objectArray = new Array()
            let jsonObjectArray = new Array()
            let arr = $('[name="id"]');//获取相同bainame的对象，然后再遍du历这个数组就zhi行了。dao
            for (let i = 0; i < arr.length; i++) {
                let val = $(arr[i]).val();//获取value值
                let obj = {id: val};
                objectArray.push(obj);
            }
            let valueArr = $('[name="value"]');//获取相同bainame的对象，然后再遍du历这个数组就zhi行了。dao
            for (let i = 0; i < valueArr.length; i++) {
                let val = $(valueArr[i]).val();//获取value值
                let obj = objectArray[i];
                obj.value = val;
                jsonObjectArray.push(obj);
            }
            js.post({
                url: ctx + 'accountManage/saveParameters',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: {
                    jsonParams: JSON.stringify(jsonObjectArray),
                    batId: $("#btn-save-edit").attr("data")
                },
                async: true,                // 异步执行
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        $("#parameterDisplayPanel").empty();
                        for (let i = 0; i < result.data.length; i++) {
                            let item = result.data[i];
                            $("#parameterDisplayPanel").append('<div class="form-group col-sm-2">' +
                                '<label class="control-label">' + item.name + ':</label>' +
                                '<label class="control-label">' + (item.value === null ? '' : item.value) + (item.unit === null ? '' : item.unit) + '</label>' +
                                '</div>');
                        }
                        js.modal.hide('modal-edit-parameter');
                    } else {
                        js.modal.warning(result.msg);
                    }
                },
                error: function () {
                    js.modal.fail();
                }
            })
        })
        /**
         * 一键概算
         * */
        $("#btn-estimating").on('click', function () {
            bootbox.confirm("确定要概算此项目吗？", function (result) {
                if (result) {
                    js.modal.open("modal-lock");
                    js.post({
                        content: "确定要核算此项目吗？",
                        url: ctx + 'estimateManage/startEstimating',
                        type: 'post',
                        traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                        dataType: 'json',
                        contentType: "application/x-www-form-urlencoded",
                        data: {
                            batId: $("#batId").val()
                        },
                        async: true,                // 异步执行
                        success: function (result) {
                            if (result.type === web_status.SUCCESS) {
                                js.modal.success(result.msg);
                            } else {
                                js.modal.warning(result.msg);
                            }
                            loadCostSheet();
                            js.modal.hide("modal-lock");
                        },
                        error: function () {
                            js.modal.fail();
                        }
                    });
                }
            });
        });
        /**
         * 成本项保存
         */
        $("#btn-costItem-save").on('click', function () {
            js.post({
                url: ctx + 'accountManage/saveCostItem',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: $("#edit-form").serialize(),
                async: true,                // 异步执行
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        loadCostSheet();
                        // $("body").scrollTop($(document).scrollTop());
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.hide("modal-item-edit");
                },
                error: function () {
                    js.modal.fail();
                }
            })
        });
        /**
         * 成本项添加
         */
        $("#btn-costItem-add-save").on('click', function () {
            var $this = $(this);
            $this.attr('disabled', true);
            js.validSubmit({
                formId: "add-form",
                url: ctx + "accountingInfo/addCostItem",
                data: new FormData($("#add-form")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.modal.hide("modal-item-add");
                        loadCostSheet();
                        $this.attr('disabled', false);
                    } else {
                        js.modal.warning(result.msg);
                        loadCostSheet();
                        $this.attr('disabled', false);
                    }
                }
            });


        });

        /**
         *  保存核算清单
         **/
        $("#btn-save-estimating").on("click", function () {
            js.confirmPost({
                content: '尊敬的用户，保存概算成本清单后则不能返回修改，您是否保存成本清单？',
                url: ctx + 'accountManage/saveEstimatingCost',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: {
                    id: $("#batId").val()
                },
                async: true,                // 异步执行
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {

                        location.href = ctx + 'estimateManage/submitList';
                    }
                },
                error: function () {
                    js.modal.fail();
                }
            });
        });
        /**
         * 全屏/取消全屏
         */
        $('body').keydown(function(event) {
            var curKey = event.which;
            if(curKey==122){
                debugger
                if(isFull()) {
                    $('#btn-full-screen').attr('screen-status',"全屏");
                    $('#btn-full-screen').text("点击取消全屏");
                    $('#btn-full-screen').attr("class","btn btn-warning btn-xs");
                } else {
                    $('#btn-full-screen').attr('screen-status',"未全屏");
                    $('#btn-full-screen').text("点击全屏");
                    $('#btn-full-screen').attr("class","btn btn-success btn-xs");
                }
            }
        });
        /**
         *  全屏/非全屏
         **/
        $("#btn-full-screen").on("click", function () {
            var element = document.documentElement;     // 返回 html dom 中的root 节点 <html>
            if($('#btn-full-screen').attr('screen-status')==='未全屏') {
                $('#btn-full-screen').attr('screen-status',"全屏");
                $('#btn-full-screen').text("点击取消全屏");
                $('#btn-full-screen').attr("class","btn btn-warning btn-xs");
                // 判断浏览器设备类型
                if(element.requestFullscreen) {
                    element.requestFullscreen();
                } else if (element.mozRequestFullScreen){   // 兼容火狐
                    element.mozRequestFullScreen();
                } else if(element.webkitRequestFullscreen) {    // 兼容谷歌
                    element.webkitRequestFullscreen();
                } else if (element.msRequestFullscreen) {   // 兼容IE
                    element.msRequestFullscreen();
                }
            } else {
                $('#btn-full-screen').attr('screen-status',"未全屏");
                $('#btn-full-screen').text("点击全屏");
                $('#btn-full-screen').attr("class","btn btn-success btn-xs");
                if(document.exitFullscreen) {
                    document.exitFullscreen();
                } else if (document.mozCancelFullScreen) {
                    document.mozCancelFullScreen();
                } else if (document.webkitCancelFullScreen) {
                    document.webkitCancelFullScreen();
                } else if (document.msExitFullscreen) {
                    document.msExitFullscreen();
                }
            }
        });
        /**
         * 查看成本清单
         **/
        $("#btn-show-cost-sheet").on('click', function (e) {
            location.href = ctx + 'accountManage/showAccCostSheet/' + $("#batId").val();
        });
        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-item-add", function () {
            js.validate.reset("add-form");
            js.reset("add-form");
        });
        /** 导入表单验证 */
        js.validate.init("add-form", {
            fields: {
                name: {
                    validators: {
                        notEmpty: {message: '请填写名称！'}
                    }
                },
                trueAmount: {
                    validators: {
                        notEmpty: {message: '请填写真实金额！'}
                    }
                }
            }
        });
        /**
         * 保存主要参数
         **/
        $("#btn-save-mainParameter").on('click', function (e) {
            js.confirmPost({
                content: '尊敬的用户，您确认要保存主要参数吗？',
                url: ctx + 'accountManage/saveMainParameter',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: {
                    id: $("#batId").val(),
                    mainParam: $("#mainParameter").val()
                },
                async: true,                // 异步执行
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        loadMainParam();
                    }
                },
                error: function () {
                    js.modal.fail();
                }
            });
        });

    });

    /**
     * 打开计算参数编辑面板
     * @param obj
     */
    function showEditCalculationParameter(obj) {
        let batId = $(obj).attr("data");
        js.post({
            url: ctx + 'accountManage/getParameters',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                batId: batId
            },
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    $("#edit-parameter-form-items").empty();
                    for (let i = 0; i < result.data.length; i++) {
                        let item = result.data[i];
                        //如果是机加定额则设置默认机加定额为列表显示
                        if (item.code === 'Machining quota') {
                            js.post({
                                url: ctx + 'accountingInfo/getMachiningQuotaData',
                                type: 'post',
                                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                                dataType: 'json',
                                contentType: "application/x-www-form-urlencoded",
                                data: {},
                                async: true,                // 异步执行
                                success: function (result) {
                                    if (result.type === web_status.SUCCESS) {
                                        $("#edit-parameter-form-items").append('<div class="form-group col-sm-6 form-horizontal">' +
                                            '<label class="control-label col-sm-6" style="margin-top:5px">' + item.name + ':</label>' +
                                            '<label class="control-label col-sm-4">' +
                                            '<select id="select_machining_quota" name="value" class="form-control select2" style="width: 200px" type="text"></select>' +
                                            '</label>' +
                                            '<label class="control-label col-sm-2" style="margin-top:5px;">' + (item.unit == null ? '' : item.unit) + '</label>' +
                                            '<input name="id" type="hidden" value="' + item.id + '"/>' +
                                            '</div>');
                                        $("#select_machining_quota").empty();
                                        let optionArray = new Array();
                                        for (var i = 0; i < result.data.rows.length; i++) {
                                            if (i === 0) {
                                                optionArray.push('<option value="">&nbsp;&nbsp;--请选择--&nbsp;&nbsp;</option>');
                                            }
                                            if (result.data.rows[i].code === item.value) {
                                                optionArray.push('<option selected="selected" value="' + result.data.rows[i].code + '">' + result.data.rows[i].version + '</option>');
                                            } else {
                                                optionArray.push('<option value="' + result.data.rows[i].code + '">' + result.data.rows[i].version + '</option>');
                                            }
                                        }
                                        $("#select_machining_quota").append(optionArray.join(" "));

                                    }
                                },
                                error: function () {
                                    js.modal.fail();
                                }
                            });
                        } else {
                            $("#edit-parameter-form-items").append('<div class="form-group col-sm-6 form-horizontal">' +
                                '<label class="control-label col-sm-6" style="margin-top:5px">' + item.name + ':</label>' +
                                '<label class="control-label col-sm-4">' +
                                '<input name="value" class="form-control" style="width: 200px" type="text" oninput="formatNumber(this)" value="' + (item.value == null ? '' : item.value) + '"/>' +
                                '</label>' +
                                '<label class="control-label col-sm-2" style="margin-top:5px;">' + (item.unit == null ? '' : item.unit) + '</label>' +
                                '<input name="id" type="hidden" value="' + item.id + '"/>' +
                                '</div>');
                        }
                    }
                    js.modal.open('modal-edit-parameter');
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 跳转到对应明细页
     * @param id
     */
    function info(obj) {
        if (hasP('rou:detail:edit')) {
            $(obj).parent().parent().find('td').removeClass('bg-orange');
            $(obj).parent().parent().find('td').addClass('bg-orange');
            window.open(ctx + "estimateManage/viewInfo/edit/" + $(obj).attr("data"));
        } else {
            js.modal.warning("尊敬的用户，您无权查看此明细。");
        }
    }

    /**
     * 编辑
     * @param id
     */
    function edit(obj) {
        let id = $(obj).attr("data");
        js.post({
            url: ctx + 'accountManage/getCostInfo',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                id: id
            },
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    let costInfo = result.data;
                    switch (costInfo.code) {
                        case "mechanicalPart-manufacturingCost-blanking":
                        case "fluidPart-manufacturingCost-blanking":
                        case "automationPart-manufacturingCost-blanking":
                            // $("#cutAlgorithmType").show();
                            break;
                    }
                    if (costInfo.priceEditFlag != 1) {
                        $("#price").hide();
                    } else {
                        $("#price").show();
                    }
                    if (costInfo.numEditFlag != 1) {
                        $("#num").hide();
                    } else {
                        $("#num").show();
                    }
                    if (costInfo.totalPriceFlag != 1) {
                        $("#totalPrice").hide();
                    } else {
                        $("#totalPrice").show();
                    }
                    if (costInfo.textureEditFlag != 1) {
                        $("#texture").hide();
                    } else {
                        $("#texture").show();
                    }
                    $("#edit-form").fillSpan(costInfo);
                    $("#edit-form").fillData(costInfo);
                    js.modal.open("modal-item-edit");

                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 不可输入空格
     */
    function handlingSpaces(obj) {
        $(obj).val().replace(/(^[\s\n\t]+|[\s\n\t]+$)/g, "")
        $(obj).val($(obj).val().replace("-",""));
    }

    /**
     * 验证输入有效的整数和四位小数
     */
    function formatNumber(obj) {
        obj.value = obj.value.replace(/[^-\d.]/g, "");  //清除“数字”和“.”以外的字符
        obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
        obj.value = obj.value.replace(/\-{2,}-/g, "-"); //只保留第一个. 清除多余的
        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d\d\d).*$/, '$1$2.$3');//只能输入两个小数
        if (obj.value.indexOf(".") < 0 && obj.value != "") {//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
            obj.value = obj.value;
        }
        //如果上去就写- 自动替换
        if (obj.value.indexOf("-") >= 0) {
            obj.value = obj.value.replace('-', "");
        }
        //如果上去就写.   自动补个0   形成0.
        if (obj.value.indexOf(".") == 0) {
            obj.value = "0" + obj.value;
        } else if (obj.value.indexOf(".") > 1) {
            //如果输入01.3自动变成1.3，自动去除整数部分的0
            if (obj.value.indexOf("0") == 0) {
                obj.value = obj.value.substr(1, obj.value.length - 1);
            }
        }
        //如果输入023直接变成23;自动去除整数部分的0
        if (obj.value.length > 2 && obj.value.indexOf(".") < 0) {
            if (obj.value.indexOf("0") == 0) {
                obj.value = obj.value.substr(1, obj.value.length - 1);
            }
        }
    }

    /**
     * 去掉小数点后面多余的0
     * @param number
     * @returns {number}
     */
    function dealingWithDecimals(number) {
        return parseFloat(number);
    }

    /**
     * 成本项显示模式
     * @param obj
     */
    function switchModel() {
        loadCostSheet();
    }

    /**
     * 金额显示模式
     * @param obj
     */
    function switchAmountModel(obj) {
        js.post({
            url: ctx + 'accountingInfo/switchAmountModel',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                batId: $("#batId").val(),
                amountDisplayModel: $(obj).val()
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    loadCostSheet();

                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }


    /**
     * 加载控制显示单位下拉菜单
     */
    function loadControlDropDownMenuDisplayParameters() {
        js.post({
            url: ctx + 'accountingInfo/loadControlDropDownMenuDisplayParameters',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                batId: $("#batId").val()
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    if (result.data != parseInt($("#listDisplayAmountMode").val())) {
                        $('#listDisplayAmountMode').selectpicker('val', result.data);
                    }
                    let priceUnit = $("#listDisplayAmountMode").val();
                    if (priceUnit === '1') {
                        $("#priceUnit").text("（元）");
                    } else if (priceUnit === '2') {
                        $("#priceUnit").text("（万元）");
                    }
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 加载净重总重参数
     */
    function loadWeightParams() {
        js.post({
            url: ctx + 'estimateManage/loadWeightParams',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                batId: $("#batId").val()
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    $("#equipmentTotalWeight").text(result.data.weight + "吨");
                    $("#equipmentTotalNetWeight").text(result.data.netWeight + "吨");
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 加载页面参数
     */
    function loadConfigParams() {
        js.post({
            url: ctx + 'accountingInfo/loadConfigParams',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                batId: $("#batId").val()
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    $("#parameterDisplayPanel").empty();
                    let configList = result.data;
                    configList.forEach(function (item, index, arr) {
                        $("#parameterDisplayPanel").append('<div class="form-group col-sm-2"<label class="control-label">' + item.name + ':</label><label class="control-label">' + (item.value == null ? '' : item.value) + '' + (item.unit == null ? '' : item.unit) + '</label></div>');
                    });
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 加载主要参数
     */
    function loadMainParam() {
        js.post({
            url: ctx + 'accountingInfo/loadMainParam',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                batId: $("#batId").val()
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    $("#mainParameter").val(result.data);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 打开的页面调用
     */
    function loadCostSheetFun(costId) {
        costIdAll = costId
        loadCostSheet();

    }

    /**
     * 加载成本清单
     * @param mode 模式：1是全部，
     */
    function loadCostSheet() {
        let mode = $("#listDisplayMode").val();
        js.post({
            url: ctx + 'estimateManage/loadCostSheet',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                batId: $("#batId").val()
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    if (result.data.length > 0) {
                        let space = '';
                        let list = result.data;
                        $("#all").empty();
                        $("#all").html('<table id="costSheet" bgcolor="#ffffff" style="border:none;  background: #FFFFFF; font-size:14px; color: #000000; text-align: center; width: 100%;font-family: \'微软雅黑\'"></table>');
                        $("#costSheet").append('<thead id="costSheetHead"> <tr parentcode="总计">' +
                            '<th style="border:1px #000000 solid;width: 100px;padding: 4px;text-align: center;height: 50px;">序号</th>' +
                            '<th style="border:1px #000000 solid;width: 140px;padding: 4px;text-align: center;">名称</th>' +
                            '<th style="border:1px #000000 solid;text-align: center;width:130px;">材质</th>' +
                            '<th style="border:1px #000000 solid;width:50px;text-align: center">单位</th>' +
                            '<th style="border:1px #000000 solid;width: 80px;text-align: center">数量</th>' +
                            '<th style="border:1px #000000 solid;width: 100px;text-align: center">单价<span id="priceUnit">（元）</span></th>' +
                            '<th style="border:1px #000000 solid;width: 160px;text-align: center">总价<span  id="totalPriceUnit">（元）</span></th>' +
                            '<th style="border:1px #000000 solid;width: 160px;text-align: center">真实金额<span  id="totalPriceUnit">（元）</span></th>' +
                            '<th style="border:1px #000000 solid;text-align: center;width:200px;">备注</th>' +
                            '<th style="border:1px #000000 solid;text-align: center;width:200px;">附加信息</th>' +
                            '<th style="border:1px #000000 solid;text-align: center;width:65px;">数据来源</th>' +
                            '<th style="border:1px #000000 solid;text-align: center;width:65px;">执行状态</th>' +
                            '<th style="border:1px #000000 solid;text-align: center;width:85px;">操作</th>' +
                            '<th style="background-color:white;text-align: center;padding: 4px;text-align: left;height: 45px;width:50px;border:0"></th>' +
                            '</tr></thead><tbody id="costSheetBody"></tbody>');
                        let tableContent = new Array();
                        let partStyle;
                        let partStyleOper;
                        let dataSource;
                        let remark;
                        let diyRemark;
                        let status;
                        let viewInfoFlag;
                        let remarkEditFlag;
                        let addOrSub;
                        let rankTopOrderNo = 0;
                        let rankSecondOrderNo = 0;
                        let rankThirdOrderNo = 0;
                        let rankFourthOrderNo = 0;
                        let rankFifthOrderNo = 0;
                        list.forEach(function (item, index, arr) {
                            addOrSub = '';
                            if (parseInt(mode) === 1 && (item.isEffectiveFlag === null || item.isEffectiveFlag === 0 )) {
                            // if (parseInt(mode) === 1 && (item.isEffectiveFlag === null || item.isEffectiveFlag === 0 || item.displayTotalPrice === null || item.displayTotalPrice === '' || parseFloat(item.displayTotalPrice) === 0)) {
                                return false;
                            }else if(item.isEffectiveFlag === null || item.isEffectiveFlag === 0 ){
                                addOrSub += '<button onclick="recoveryThisRow(this)" style="color:#00a65a;background: transparent;outline: none;border:none;"><i class="fa fa-history"></i></button>';
                            }
                            if (item.isPart === 1) {
                                partStyle = 'class="bg-aqua" style="border:1px #000000 solid;text-align: center;padding: 4px;text-align: center;height: 45px;"';
                                partStyleOper = 'class="bg-aqua" style="border:1px #000000 solid;text-align: left;padding: 4px;text-align: left;height: 45px;"';
                            } else {
                                partStyle = 'style="border:1px #000000 solid;text-align: center;padding: 4px;text-align: center;height: 45px;"';
                                partStyleOper = 'style="border:1px #000000 solid;text-align: center;padding: 4px;text-align: left;height: 45px;"';
                            }
                            if (item.dataSource === '1' && item.showDataSource === 1) {
                                dataSource = '<label class="badge label-success">有数据</label>';
                            } else if (item.dataSource === '0' && item.showDataSource === 1) {
                                dataSource = '<label class="badge label-default">无数据</label>';
                            } else {
                                dataSource = '';
                            }
                            if (item.isInvalid === 1) {
                                remark = '作废';
                            } else if (item.remark != null) {
                                remark = item.remark;
                            } else if (item.remark === null) {
                                remark = '';
                            }
                            if (item.diyRemark != null) {
                                diyRemark = item.diyRemark;
                            } else {
                                diyRemark = '';
                            }
                            if (item.showFinishStatus === 1 && item.finishStatus === 1) {
                                status = '<label class="badge label-default">未开始</label>';
                            } else if (item.showFinishStatus === 1 && item.finishStatus === 2) {
                                status = '<label class="badge label-warning">执行中</label>';
                            } else if (item.showFinishStatus === 1 && item.finishStatus === 3) {
                                status = '<label class="badge label-success">已完成</label>';
                            } else {
                                status = '';
                            }
                            if (hasP('ver:detail:view')) {
                                if (item.viewInfoFlag === 1) {
                                    viewInfoFlag = '<button class="btn btn-success btn-xs" onclick="info(this)" data="' + item.id + '">查看</button>';
                                } else {
                                    viewInfoFlag = '';
                                }
                            }
                            if (hasP('ver:adjust:edit')) {
                                if (item.remarkEditFlag === 1) {
                                    remarkEditFlag = '<button class="btn btn-warning btn-xs" data="' + item.id + '" onclick="edit(this)">编辑</button>';
                                   if (item.isEffectiveFlag == 1 && (
                                        item.code.substring(item.code.lastIndexOf("-", 0), item.code.length) === '-材料采购费' ||
                                        !item.name.includes('材料费') &&
                                        !item.parentCode.includes('-材料采购费') &&
                                        !item.code.includes('小计') &&
                                        !item.code.includes('-材料费-废料回收费') &&
                                        !item.parentCode.includes('-材料费-废料回收费') &&
                                        !item.code.includes('-外购费') &&
                                        !item.parentCode.includes('-制造费') &&
                                        !item.parentCode.includes('-外协费') &&
                                        !item.parentCode.includes('-现场安装费') &&
                                        !item.code.includes('-设计费') &&
                                        !item.code.includes('包装运输费') &&
                                        !item.code.includes('备品备件') &&
                                        !item.code.includes('随机备件') &&
                                        !item.code.includes('管理费') &&
                                        !item.code.includes('保运费') &&
                                        !item.code.includes('不可预见费'))
                                    ) {
                                        addOrSub = '<button onclick="addChildRow(this)" style="color:#00a65a;background: transparent;outline: none;border:none;"><i class="fa fa-plus"></i></button>';
                                        addOrSub += '<button onclick="subThisRow(this)" style="color:#dd4b39;background: transparent;outline: none;border:none;"><i class="fa fa-minus"></i></button>';
                                    } else {
                                        addOrSub += '<button onclick="subThisRow(this)" style="color:#dd4b39;background: transparent;outline: none;border:none;"><i class="fa fa-minus"></i></button>';
                                    }
                                    // remarkEditFlag += '<button style="color:#00a65a;background: transparent;outline: none;border:none;"><i class="fa fa-arrow-up"></i></button>';
                                    // remarkEditFlag += '<button style="color:#dd4b39;background: transparent;outline: none;border:none;"><i class="fa fa-arrow-down"></i></button>';
                                } else {
                                    if (item.code === '合计') {
                                        remarkEditFlag = '';
                                        addOrSub = '<button onclick="addChildRow(this)" style="color:#00a65a;background: transparent;outline: none;border:none;"><i class="fa fa-plus"></i></button>';
                                        addOrSub += '<button onclick="subThisRow(this)" style="color:#dd4b39;background: transparent;outline: none;border:none;"><i class="fa fa-minus"></i></button>';
                                    } else {
                                        remarkEditFlag = '';
                                        addOrSub += '<button onclick="subThisRow(this)" style="color:#dd4b39;background: transparent;outline: none;border:none;"><i class="fa fa-minus"></i></button>';
                                    }
                                }
                            }
                            if (hasP('ver:detail:view') && hasP('ver:adjust:edit')) {
                                if (item.viewInfoFlag === 1 && item.remarkEditFlag === 1) {
                                    space = '&nbsp;&nbsp;';
                                }
                            }
                            let editShowOrderNo = item.editShowOrderNo;
                            // if (item.editShowOrderNo === null) {
                            //     editShowOrderNo = '';
                            // } else
                            if (item.rank === 1) {
                                rankTopOrderNo++;
                                editShowOrderNo = xyh.toChinesNumFun(rankTopOrderNo);
                                rankSecondOrderNo = 0;
                                rankThirdOrderNo = 0;
                            } else if (item.rank === 2) {
                                rankSecondOrderNo++;
                                editShowOrderNo = "（" + xyh.toChinesNumFun(rankSecondOrderNo) + "）";
                                rankThirdOrderNo = 0;
                            } else if (item.rank === 3) {
                                rankThirdOrderNo++;
                                editShowOrderNo = rankThirdOrderNo;
                                rankFourthOrderNo = 0;
                            } else if (item.rank === 4) {
                                rankFourthOrderNo++;
                                editShowOrderNo = rankThirdOrderNo + "." + rankFourthOrderNo;
                                rankFifthOrderNo = 0;
                            } else if (item.rank === 5) {
                                rankFifthOrderNo++;
                                editShowOrderNo = rankThirdOrderNo + "." + rankFourthOrderNo + "." + rankFifthOrderNo;
                            }
                            let name = item.name;
                            if (item.name === null) {
                                name = '';
                            }
                            let texture = item.texture;
                            if (item.texture === null) {
                                texture = '';
                            }
                            let unit = item.unit;
                            if (item.unit === null) {
                                unit = '';
                            }
                            let displayNum = item.displayNum;
                            if (item.displayNum === null) {
                                displayNum = '';
                            }
                            let displayPrice = item.displayPrice;
                            if (item.displayPrice === null) {
                                displayPrice = '';
                            }
                            let displayTotalPrice = item.displayTotalPrice;
                            if (item.displayTotalPrice === null) {
                                displayTotalPrice = '';
                            }
                            let trueAmount = item.displayTrueAmount;
                            if (item.displayTrueAmount === null) {
                                trueAmount = '';
                            }
                            let beginTag;
                            let endTag;
                            if (item.isPart === 1) {
                                beginTag = '<th';
                                endTag = '</th>';
                            } else {
                                beginTag = '<td';
                                endTag = '</td>';
                            }
                            if (item.isMajor === 1) {
                                beginTag = '<th';
                                endTag = '</th>';
                            } else {
                                beginTag = '<td';
                                endTag = '</td>';
                            }
                            let colspanHtml = '';
                            if (item.code.includes('小计') || item.code.includes('合计')) {
                                colspanHtml = ' colspan="2" ';
                            }
                            if (item.code.includes('小计') || item.code.includes('合计')) {
                                tableContent.push('<tr draggable="true" id="dataRow_' + item.id + '" parentCode="' + item.parentCode + '" code = "' + item.code + '" data-id = "' + item.id + '">' +
                                    beginTag + ' name="name" ' + colspanHtml + ' ' + partStyle + '><a name="a_' + item.id + '"></a>' + name + endTag +
                                    beginTag + ' name="texture" ' + partStyle + '>' + texture + endTag +
                                    beginTag + ' name="unit" ' + partStyle + '>' + unit + endTag +
                                    beginTag + ' name="num" ' + partStyle + '>' + displayNum + endTag +
                                    beginTag + ' name="price" ' + partStyle + '>' + displayPrice + endTag +
                                    beginTag + ' name="displayTotalPrice" ' + partStyle + '>' + displayTotalPrice + endTag +
                                    beginTag + ' name="trueAmount" ' + partStyle + '>' + trueAmount + endTag +
                                    beginTag + ' name="remark"  ' + partStyle + '>' + remark + endTag +
                                    beginTag + ' name="diyRemark"  ' + partStyle + '>' + diyRemark + endTag +
                                    beginTag + ' name="dataSource" ' + partStyle + ' >' + dataSource + endTag +
                                    beginTag + ' name="finishStatus" ' + partStyle + ' >' + status + endTag +
                                    beginTag + ' name="operation" ' + partStyleOper + ' >' + viewInfoFlag + space + remarkEditFlag + endTag +
                                    beginTag + ' name="addOrSub" style="border:none;text-align: center;padding: 4px;text-align: left;height: 45px;">' + addOrSub + endTag +
                                    '</tr>');
                            } else {
                                tableContent.push('<tr draggable="true" id="dataRow_' + item.id + '" parentCode="' + item.parentCode + '" code = "' + item.code + '" data-id = "' + item.id + '">' +
                                    beginTag + ' name="editShowOrderNo" ' + partStyle + '><a name="a_' + item.id + '"></a>' + editShowOrderNo + endTag +
                                    beginTag + ' name="name" ' + partStyle + '>' + name + endTag +
                                    beginTag + ' name="texture" ' + partStyle + '>' + texture + endTag +
                                    beginTag + ' name="unit" ' + partStyle + '>' + unit + endTag +
                                    beginTag + ' name="num" ' + partStyle + '>' + displayNum + endTag +
                                    beginTag + ' name="price" ' + partStyle + '>' + displayPrice + endTag +
                                    beginTag + ' name="displayTotalPrice" ' + partStyle + '>' + displayTotalPrice + endTag +
                                    beginTag + ' name="trueAmount" ' + partStyle + '>' + trueAmount + endTag +
                                    beginTag + ' name="remark"  ' + partStyle + '>' + remark + endTag +
                                    beginTag + ' name="diyRemark"  ' + partStyle + '>' + diyRemark + endTag +
                                    beginTag + ' name="dataSource" ' + partStyle + ' >' + dataSource + endTag +
                                    beginTag + ' name="finishStatus" ' + partStyle + ' >' + status + endTag +
                                    beginTag + ' name="operation" ' + partStyleOper + ' >' + viewInfoFlag + space + remarkEditFlag + endTag +
                                    beginTag + ' name="addOrSub" style="border:none;text-align: center;padding: 4px;text-align: left;height: 45px;">' + addOrSub + endTag +
                                    '</tr>');
                            }
                        });
                        $("#costSheetBody").append(tableContent.join(''));
                        let priceUnit = $("#listDisplayAmountMode").val();
                        if (priceUnit === '1') {
                            $("#priceUnit").text("（元）");
                            $("#totalPriceUnit").text("（元）");
                        } else if (priceUnit === '2') {
                            $("#priceUnit").text("（万元）");
                            $("#totalPriceUnit").text("（万元）");
                        }
                        loadNote();
                        bindScrollHandle();
                        $("#costSheet").dragSort();
                        if (costIdAll != undefined) {
                            $("#dataRow_" + costIdAll).find('td').removeClass('bg-orange');
                            $("#dataRow_" + costIdAll).find('td').addClass('bg-orange');
                            $("html,body").scrollTop($("#dataRow_" + costIdAll).offset().top - 50);
                        }
                    }
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 加载注：的内容
     */
    function loadNote() {
        js.post({
            url: ctx + 'accountingInfo/loadNote',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                batId: $("#batId").val()
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    let order = result.data;
                    if ($("#noteRow") != undefined) {
                        $("#noteRow").remove();
                    }
                    $("#all").append('<div id="noteRow" class="row"><form id="noteForm" class="form-horizontal"></form></div>');
                    $("#noteForm").append('<div class="row"><div id="priceRange" class="form-inline"></div></div>');
                    $("#priceRange").append('<div class="form-group"><label class="control-label">注：</label>' +
                        '<label class="control-label">1：价格范围：</label>' +
                        '<label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangeDesignFlag" value="1"/></label>' +
                        '<label class="control-label">设计</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangeMateriaFlag" value="1"/></label>' +
                        '<label class="control-label">材料</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangeManufactureFlag" value="1"/></label>' +
                        '<label class="control-label">制造</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangePackingFlag" value="1"/></label>' +
                        '<label class="control-label">包装</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangeTransportFlag" value="1"/></label>' +
                        '<label class="control-label">运输</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangeInstall" value="1"/></label>' +
                        '<label class="control-label">安装</label>&nbsp;&nbsp;' +
                        '<label class="control-label">（&nbsp;</label><label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangeInstallBusinessTravelSubsidyFlag" value="1"/></label>' +
                        '<label class="control-label">出差补助</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangeInstallAccommodationFlag" value="1"/></label>' +
                        '<label class="control-label">食宿</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangeInstallBusinessTravelFlag" value="1"/></label>' +
                        '<label class="control-label">差旅</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangeInstallHoistingFlag" value="1"/></label>' +
                        '<label class="control-label">吊装</label><label class="control-label">&nbsp;）</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangeDebugFlag" value="1"/></label>' +
                        '<label class="control-label">调试</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangeSparePartsFlag" value="1"/></label>' +
                        '<label class="control-label">备品备件</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><input type="checkbox" onclick="changeValue(this)" name="priceRangeTransportGuaranteeFlag" value="1"/></label>' +
                        '<label class="control-label">保运</label>' +
                        '</div>');
                    $("#noteForm").fillData(order);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 锁定表头
     */
    function bindScrollHandle() {
        $(window).on('scroll', function () {
            let scrollSize = $(window).scrollTop() - 310.25 - $("#basicInfoPanel").height() - $("#mainParameterPanel").height();
            if (scrollSize >= 0) {
                $('#costSheetHead').attr("style", "transform: translateY(+" + scrollSize + "px);");
            } else {
                $('#costSheetHead').attr("style", "");
            }
        })
    }

    /**
     * 更改note值
     * @param obj
     */
    function changeValue(obj) {
        if ($(obj).prop("checked")) {
            $(obj).val(1);
        } else {
            $(obj).val(0);
        }
        let checkBoxName = $(obj).attr("name");
        toChange(checkBoxName, $(obj).val());
    }

    /**
     * 执行更改note值
     * @param obj
     */
    function toChange(field, val) {
        js.post({
            url: ctx + 'accountingInfo/toChange',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                id: $("#batId").val(),
                field: field,
                fieldValue: val
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    loadNote();
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 添加子集
     * @param obj
     */
    function addChildRow(obj) {
        let row = $(obj).parent().parent();
        createNewItem(row.attr('code'));
        // let rowHtml = $(obj).parent().parent().prop("outerHTML");
        // row.after(rowHtml);
    }

    /**
     * 删除本身
     * @param obj
     */
    function subThisRow(obj) {
        js.post({
            url: ctx + 'accountingInfo/deleteCostItem',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                id: $(obj).parent().parent().attr('data-id')
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    loadCostSheet();
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 创建新行
     */
    function createNewItem(code) {
        $("#add-form [name='parentCode']").val(code);
        $("#add-form [name='batId']").val($("#batId").val());
        js.modal.open('modal-item-add');
    }
    /**
     * 恢复成有效
     */
    function recoveryThisRow(obj){
        js.post({
            url: ctx + 'accountingInfo/recovery',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                id: $(obj).parent().parent().attr('data-id')
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    loadCostSheet();
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    // /**
    //  * 定位器
    //  */
    // function positioner(costId) {
    //     window.location.hash = "#a_" + costId;
    // }

    function isFull(){
        if(document.body.scrollHeight==window.screen.height&&document.body.scrollWidth==window.screen.width){
           return true;
        }else{
            return false;
        }
    }
</script>
</body>
</html>